<template>
  <div>
    <!-- <TopFilter
      :list="topFilterList"
      :cols="2"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
    ></TopFilter> -->

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn='false'
      :onColumnsChange="columns => this.columns = columns"
    >
      <template slot="controls" slot-scope="props">
        <el-button size="small" type="primary" v-show="isShowCZ" @click="addHandle">新增</el-button>
      </template>
    </FilterTable>
    <BaseDialog
      :visible.sync="visible"
      :title="dialogTitle"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <followTaskModal :type="handleType" :rowData="formData" @close="closeHandler" />
    </BaseDialog>
    <!-- <el-dialog
      :visible.sync="delVisible"
      title="删除"
      :type="handleType"
      :rowData="formData"
      width="30%"
      center>
      <span>确定要删除吗?</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="closeVisible">取 消</el-button>
        <el-button type="primary" @click="deleteHandler">确 定</el-button>
      </span>
    </el-dialog> -->
  </div>
</template>

<script>
import {
  queryTrackingTask,
  queryTrackingTaskByid,
  addTrackingTask,
  modifyTrackingTask
 } from '@/api/potenCus/basedata/followTask';
import { dictionary } from '@/utils/dictMixin';
import { getDataType } from '@/assets/js/auth';
import followTaskModal from './followTaskModal';
export default {
  name: 'followTask',
  mixins: [dictionary],
  components: {
    followTaskModal
  },
  data() {
    return {
      dataType: getDataType('dataType'),
      // topFilterList: this.createTopFilters(),
      fetchParams: { type:1 },
      visible: false,
      delVisible: false,
      isShowCZ: false,
      dialogTitle: '',
      fetchApi: queryTrackingTask,
      columns: this.createTableColumns(),
      handleType: '',
      formData: {},
      conf:{ add: '新增', edit: '编辑', delete: '删除' },
    };
  },
  created() {
    this.isShowCZData()
    this.init()
  },
  methods: {
    init(){
      console.log('dataType', this.dataType)
        this.columns.unshift(
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 60,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.editHandle(props.row)}>
                  编辑
                </el-button>
              </div>
                // <el-divider direction="vertical" />
                // <el-button size="mini" type="text" onClick={() => this.delHandle(props.row)}>
                //   删除
                // </el-button>
            );
          }
        })
        if(this.dataType != 10461001){
          this.columns.find(x => x.dataIndex ==='shopIntervalDays').hidden = true
          this.columns.find(x => x.dataIndex ==='intervalDays').title = '间隔天数'
        }
    },
    createTopFilters() {

    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '意向级别',
          dataIndex: 'intentLevel',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1519'),
          render: props => {
            return <span>{this.createDictText(props.row.intentLevel, '1519')}</span>;
          }
        },
        {
          title: '所属意向类型',
          dataIndex: 'taskId',
          sorter: true,
          filterType: 'input',
          render: props => {
            return <span>{this.dict['1519'].find(x => x.codeId == props.row.intentLevel)['codeEnDesc']}</span>;
          }
        },
        {
          title: '间隔天数(须小于等于默认值)',
          dataIndex: 'shopIntervalDays',
          sorter: true,
          filter: true,
          hidden: false,
          // editable: true,
          // editType: 'number',
          // editPattern: /^\+?[1-9][0-9]*$/,
          filterType: 'input',
          // render: props => {
          //   return <el-input value={props.row.shopIntervalDays} placeholder="" onInput={(e)=>{
          //     console.log('天数', e)
          //     props.row.vehiclePrice = Number(e)
          //   }}></el-input>
          // }
        },
        {
          title: '间隔天数(默认)',
          dataIndex: 'intervalDays',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '意向类型名称',
          dataIndex: 'taskName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '是否有效',
          dataIndex: 'isValid',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.isValid, '1004')}</span>;

          }
        }
      ];
    },
    isShowCZData() {
      // console.log('dataType', this.dataType)
      if(this.dataType == 10461003){
        this.isShowCZ = true
      } else {
        this.isShowCZ = false
      }
    },
    addHandle() {
      this.handleType = 'add';
      this.showHandler();
    },
    editHandle(row) {
      this.handleType = 'edit';
      this.formData = row;
      this.showHandler();
    },
    delHandle(row) {
      this.handleType = 'delete';
      this.formData = row;
      this.taskId = row.taskId
      this.delVisible = true;
    },
    // async deleteRow() {
    //   const res = await modifyTrackingTask(this.formData,this.taskId, this.formData.isDeleted= 1);
    //   console.log('删除', res)
    //   if (res.resultCode === 200) {
    //     this.closeVisible();
    //     this.fetchParams = { ...this.fetchParams };
    //     this.$message.success("删除成功!");
    //   }
    // },
    // deleteHandler(){
    //   this.deleteRow()
    // },
    closeVisible(){
      this.delVisible = false;
    },
    showHandler() {
      this.dialogTitle = `跟进任务${this.conf[this.handleType]}`;
      this.visible = true;
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({ sort: 'wayId', order: 'desc'}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
};
</script>

<style lang="less" scoped>
</style>
